﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Lime;

namespace Clandestine.Graphics
{
    public class Camera
    {
        public PointF Position;
        public float Zoom = 1f;
        public float Angle = 0f;

		public Color4 BackgroundColor = Color4.Yellow;
		public Color4 Tint = Color4.White;

		public Graphics Graphics;
		
		internal Camera(Graphics graphics)
		{
			this.Graphics = graphics;
		}
		
        internal void SetMatrix()
        {
            // Put modelview matrix in editing slot, reset it.
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            // Apply scale, translate, rotate.
            // I don't think remember testing this rigorously for anything other than translate, so watch out!
            // The order of funcs may be wrong!
            GL.Scale(Zoom, Zoom, 1f);
            GL.Translate(-Position.X, -Position.Y, 0f);
            GL.Rotate(-Angle, 0f, 0f, 1f);
        }

        public void UpdateScrolling(Point focusPoint)
        {
            // scroll dat bitch
            int borderWidth = 150;
            if (focusPoint.X <= Position.X + borderWidth) // LEFT
                Position.X -= (Position.X + borderWidth) - focusPoint.X;
            if (focusPoint.X >= (Position.X + Graphics.ScreenWidth - borderWidth)) // RIGHT
                Position.X += focusPoint.X - (Position.X + Graphics.ScreenWidth - borderWidth);
            if (focusPoint.Y <= Position.Y + borderWidth) // TOP
                Position.Y -= (Position.Y + borderWidth) - focusPoint.Y;
            if (focusPoint.Y >= (Position.Y + Graphics.ScreenHeight - borderWidth)) // BOTTOM
                Position.Y += focusPoint.Y - (Position.Y + Graphics.ScreenHeight - borderWidth);
        }
    }
}
